package com.opgea.crm.services;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.opgea.crm.domain.entities.Company;
import com.opgea.crm.domain.modal.QualifierModel;
import com.opgea.crm.repository.CompanyRepo;

@Service
public class CompanyServiceImpl implements CompanyService {

	@Autowired
	CompanyRepo companyRepo;
	
	@Transactional(propagation=Propagation.REQUIRED)
	public void createCompany(Company company) {
		System.out.println("I am in Service createCompany...");
		companyRepo.createCompany(company);

	}

	public void remove(long id) {
		// TODO Auto-generated method stub
		
	}

	public Company find(long id) {
		return companyRepo.find(id); 
	}

	public List<Company> findAll() {
		return companyRepo.findAll();
	}

	public List<QualifierModel> findAllCompanyName() {
		List<Company> companies = this.findAll();
		List<QualifierModel> companyNameList = new ArrayList<QualifierModel>();
		System.out.println("inside service impl");
		for(Company company : companies)
		{
			companyNameList.add(new QualifierModel(Long.valueOf(company.getId()), company.getName()));
			//companyNameList.add(new QualifierModel(String.valueOf(company.getId()), company.getName()));
			System.out.println("Company id : "+company.getId()+", Name :"+ company.getName());
		}
		
		return companyNameList;
	}

}
